package com.atguigu.tms.mock.service.impl;

import com.atguigu.tms.mock.bean.BaseOrgan;
import com.atguigu.tms.mock.bean.EmployeeInfo;
import com.atguigu.tms.mock.bean.TruckTeam;
import com.atguigu.tms.mock.config.AppConfig;
import com.atguigu.tms.mock.constant.TmsConstant;
import com.atguigu.tms.mock.mapper.TruckTeamMapper;
import com.atguigu.tms.mock.service.BaseOrganService;
import com.atguigu.tms.mock.service.TruckTeamService;
import com.atguigu.tms.mock.service.adv.impl.AdvServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 车队表 服务实现类
 * </p>
 *
 * @author zhangchen
 * @since 2022-03-20
 */
@Service
public class TruckTeamServiceImpl extends AdvServiceImpl<TruckTeamMapper, TruckTeam> implements TruckTeamService {

    @Autowired
    BaseOrganService baseOrganService;

    @Autowired
    EmployeeInfoServiceImpl employeeInfoService;

    public  void initTruckTeam(){
        Integer teamNo=1000;

        List<BaseOrgan> baseOrganL1List = baseOrganService.getBaseOrganL1List();
        List<TruckTeam> truckTeamList=new ArrayList<>(baseOrganL1List.size());
        for (BaseOrgan baseOrgan : baseOrganL1List) {
            TruckTeam truckTeam = new TruckTeam();
            truckTeam.setTeamNo("T"+teamNo++ );
            truckTeam.setOrgId(baseOrgan.getId());
            truckTeam.setName( baseOrgan.getOrgName()+"第一车队" );
            List<EmployeeInfo> employeeInfoList = employeeInfoService.initEmployeeInfo(1, TmsConstant.POSITION_TRUCK_TEAM_MANAGER);
            EmployeeInfo employeeInfo = employeeInfoList.get(0);
            employeeInfoService.saveOrUpdate(employeeInfo,true);
            truckTeam.setManagerEmpId(employeeInfo.getId());
            truckTeam.setCreateTime(AppConfig.mock_date);
            truckTeam.setIsDeleted("0");

            truckTeamList.add(truckTeam);

        }
        saveOrUpdateBatch(truckTeamList,100,true);


    }



    @Override
    protected String getIdName() {
        return "orgId";
    }
}
